Skip to content

Decorators are parsed by the grammar: @ a, @a . b, @℘ accepted as tsc does; the decorator scope covers only @name - #209

Merged
johnsoncodehk merged 5 commits into
masterfrom
land/grammar-decorators-2
Nov 24, 2026
Merged

johnsoncodehk merged 5 commits into
masterfrom
land/grammar-decorators-2

Conversation

@johnsoncodehk

@johnsoncodehk johnsoncodehk commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

What changes

Decorators are now parsed by the grammar. Before, a whole decorator such as @a.b.c was a single lexer token, so spaces, non-ASCII names and malformed decorators were handled wrongly.

Code Before Now tsc
@ a class C {} rejected accepted accepts
@a . b class C {} rejected (JS) accepted accepts
@℘ class C {} rejected accepted accepts
@a.℘ class C {} rejected accepted accepts
@a. class C {} accepted rejected rejects
@ class C {} accepted rejected rejects
@() class C {} accepted rejected rejects

@a, @a.b.c, @a.#p, @a(1) and @(expr) behave as before.

Highlighting changes

This is visible in VS Code, Monaco and tree-sitter editors:

  • The decorator colour now covers @name only. In @a.b.c, the .b.c part is coloured like any other property access.
  • A lone @ is punctuation.

Cost

  • Speed: the emitted Rust parser executes 0.3% to 0.6% more instructions on real TypeScript files (1.3% to 1.7% on TSX), and Go 0.1% to 0.4%. The parser does exactly the same work as before; the extra comes from how the compiler lays out the lexer once @ is a punctuator of its own. Three attempts to remove it failed, and a correctness fix is not held back for it.
  • Size: emitted parsers move by about ±1%.

Known limits

  • @a℘ (ASCII followed by a non-ASCII character in one name) is still rejected; tsc accepts it.
  • @class and @this are not rejected in JavaScript (as before).

🤖 Generated with Claude Code

johnsoncodehk and others added 5 commits November 24, 2026 07:38
…egments and arguments are the grammar's (transplanted from land/grammar-decorators 5632dcd onto the rewritten history; regenerated)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… sizes re-recorded

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e literals): floors and P10 lists re-measured

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/COMPLETENESS.md
#	test/portable-recovery.ts
#	typescriptreact.tmLanguage.json
@johnsoncodehk
johnsoncodehk merged commit 6bb8170 into master Nov 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant